/* Packages */
package edu.gatech.team404.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import edu.gatech.team404.Account;
import edu.gatech.team404.Lab;
import edu.gatech.team404.dal.AccountDAL;
import edu.gatech.team404.dal.LabDAL;
import edu.gatech.team404.tool.Scheduler;

/**
 * Servlet implementation class LabDescription
 * @author Michael Dandy
 * @version 1.0
 */
@WebServlet("/LabDescription")
public class LabDescription extends HttpServlet {
	/** Serial Number */
	private static final long serialVersionUID = 1L;
       
	/** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws NumberFormatException if a number format exception occurs
     * @throws IOException if an I/O error occurs
     */
	protected void processRequest(HttpServletRequest request, 
								  HttpServletResponse response)
								  throws IOException, NumberFormatException {
        response.setContentType("text/html;charset=UTF-8");
        final PrintWriter out = response.getWriter();
        
        final LabDAL dal = new LabDAL();
        
        try {
           final String labId = request.getParameter("labId");
           Lab lab = dal.getLabById(labId);
           out.print(lab.getCourseName() + ":"
        		   + Scheduler.convertToString(lab.getStartDate()) + ":" 
        		   + Scheduler.convertToString(lab.getEndDate()) + ":"
        		   + lab.getTeamAssignment().toString() + ":"
        		   + lab.getTeamSize());
        }
        finally {
        	dal.close();
        	out.close();
        }
    }

	/** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws NumberFormatException if a number format exception occurs
     * @throws IOException if an I/O error occurs
     */
	@Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, NumberFormatException {
        processRequest(request, response);
    } 

	/** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws NumberFormatException if a number format exception occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws IOException, NumberFormatException {
        processRequest(request, response);
    }

}
